나는 약간의 도움이 필요하다. 나는 int
, 어떤 수학 연산, 어떤 숫자 및 =
표지판을 내 코드에 잡기 위해 몇 가지 Regex
표현식을 만들려고 노력하고있다. 나머지는 모두 무시한다. 무시할 단어는 false로 설정되고 다른 단어는 아래 코드와 같이 true로 설정됩니다.복잡한 정규식
정수 오버플로를 감지 할 수있는 Lexer를 구현하기 위해 위에서 언급 한 키워드를 토큰 화하는 데 사용됩니다. 나는 이것을 Regex
와 독점적으로해야합니다.
나는 이미 단어 int
, 수학 연산 및 자릿수를 성공적으로 캡처했지만 내 Regex
은 임의의 단어를 인식하지 못하는 것 같습니다. 같은
lexer.AddDefinition(new TokenDefinition(
"(operator)",
new Regex(@"\*|\/|\+|\-"),
false));
lexer.AddDefinition(new TokenDefinition(
"(literal)",
new Regex(@"\d+"),
false));
lexer.AddDefinition(new TokenDefinition(
"(Random Word)",
new Regex(@"(?=.*[A-Z])(?=.*[a-z])"),
false));
lexer.AddDefinition(new TokenDefinition(
"(integer)",
new Regex(@"\bint\b"),
false));
lexer.AddDefinition(new TokenDefinition(
"(white-space)",
new Regex(@"\s+"),
true));
// This is not working. Random words such as variable names are not being captured by this.
lexer.AddDefinition(new TokenDefinition(
"(random-word)",
new Regex(@"\b(?=.*[A-Z])(?=.*[a-z])\b"),
true));
// What about the brackets? How can I implement a Regex to capture brackets?
이 그렇게 단순하게 보이지만 내가 할 수있는 등 등 ... 문, 둥근 괄호, 중괄호, 것처럼 변수 이름 (숫자 1, 숫자 2, 등) 및 언어 내부에 다른 단어로 끝내지 마. 의견을 공유하십시오. 의견을 환영합니다.
설명을 위해 편집 됨. – ClaireG
LL (1) 파사 - 생성기 (coco/r 또는 이와 유사)를 사용하는 것에 대해 생각해 보셨습니까? http://www.thefreecountry.com/programming/compilerconstruction.shtml – TGlatzer
고마워, 저것 좀 봐야 겠어. – ClaireG