pascalabcnet/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascal.lex

623 lines
21 KiB
Plaintext
Raw Permalink Normal View History

2015-05-14 22:35:07 +03:00
%{
public PascalParserTools parserTools;
2015-05-14 22:35:07 +03:00
Stack<BufferContext> buffStack = new Stack<BufferContext>();
Stack<string> fNameStack = new Stack<string>();
Stack<bool> IfDefInElseBranch = new Stack<bool>();
Stack<string> IfDefVar = new Stack<string>();
2016-05-26 14:16:32 +03:00
public List<string> Defines = new List<string>();
2015-05-14 22:35:07 +03:00
int IfExclude;
string Pars;
LexLocation currentLexLocation;
bool HiddenIdents = false;
2024-04-07 12:02:01 +03:00
bool ExprMode = false;
2015-05-14 22:35:07 +03:00
%}
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
%namespace Languages.Pascal.Frontend.Core
2015-05-14 22:35:07 +03:00
%using PascalABCCompiler.SyntaxTree;
%using PascalABCCompiler.ParserTools;
%using QUT.Gppg;
Letter [[:IsLetter:]_]
2015-05-14 22:35:07 +03:00
Digit [0-9]
Digit_ [0-9_]
2015-05-14 22:35:07 +03:00
LetterDigit {Letter}|{Digit}
2024-04-07 21:42:57 +03:00
ID {Letter}{LetterDigit}*
2015-05-14 22:35:07 +03:00
HexDigit {Digit}|[abcdefABCDEF]
HexDigit_ {Digit}|[abcdefABCDEF_]
2015-05-14 22:35:07 +03:00
DotChr [^\r\n]
OneLineCmnt \/\/{DotChr}*
DotChr1 [^\r\n}]
NOTASCII [^\x00-x7F]
CHARACTERNUM '[^'\n]'
INTNUM {Digit}{Digit_}*
BIGINTNUM {INTNUM}[bB][iI]
2015-05-14 22:35:07 +03:00
FLOATNUM {INTNUM}\.{INTNUM}
EXPNUM ({INTNUM}\.)?{INTNUM}[eE][+\-]?{INTNUM}
STRINGNUM \'([^\'\n]|\'\')*\'
MULTILINESTRINGNUM \'\'\'[ ]*\r?\n([^']|\'[^']|\'\'[^'])*\'\'\'
2018-03-21 23:01:54 +03:00
FORMATSTRINGNUM \$\'([^\'\n]|\'\')*\'
HEXNUM ${HexDigit}{HexDigit_}*
2015-05-14 22:35:07 +03:00
SHARPCHARNUM #{Digit}+
OLDDIRECTIVE #{ID}
IFDEF \{\$ifdef\ {DotChr1}*\}
IFNDEF \{\$ifndef\ {DotChr1}*\}
ENDIF \{\$endif\}
DEFINE \{\$define\ {DotChr1}*\}
DIRECTIVE \{\${DotChr1}*\}
ALPHABET [^ a-zA-Z_0-9\r\n\t\'$#&,:.;@\+\-\*/=<>\^()\[\]\x01]
2016-01-23 08:21:09 +03:00
UNICODEARROW \x890
2015-05-14 22:35:07 +03:00
%x COMMENT
%x COMMENT1
%x COMMENTONELINE
%x INCL
%x EXCLUDETEXT
%%
{OneLineCmnt} {
}
{DIRECTIVE} {
if (parserTools.buildTreeForFormatter)
2015-05-14 22:35:07 +03:00
break;
parserTools.ParseDirective(yytext, CurrentLexLocation, out var directiveName, out var directiveParams);
var orgDirectiveName = directiveName;
if (directiveName == "") // случай пустой директивы
break;
directiveName = directiveName.ToUpper();
if (directiveName == "HIDDENIDENTS")
{
HiddenIdents = true;
}
else if (directiveName == "INCLUDE")
2015-05-14 22:35:07 +03:00
{
TryInclude(directiveParams[0]);
2015-05-14 22:35:07 +03:00
}
else if (directiveName == "IFDEF")
2015-05-14 22:35:07 +03:00
{
IfDefInElseBranch.Push(false);
IfDefVar.Push(directiveParams[0]);
if (!Defines.Contains(directiveParams[0]))
2015-05-14 22:35:07 +03:00
{
BEGIN(EXCLUDETEXT);
IfExclude = 1;
}
}
else if (directiveName == "IFNDEF")
2015-05-14 22:35:07 +03:00
{
IfDefInElseBranch.Push(false);
IfDefVar.Push(directiveParams[0]);
if (Defines.Contains(directiveParams[0]))
2015-05-14 22:35:07 +03:00
{
BEGIN(EXCLUDETEXT);
IfExclude = 1;
}
}
else if (directiveName == "ELSE")
2015-05-14 22:35:07 +03:00
{
if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek())
parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]);
if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop())
parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation);
IfDefInElseBranch.Push(true);
2015-05-14 22:35:07 +03:00
BEGIN(EXCLUDETEXT);
IfExclude = 1;
}
else if (directiveName == "ENDIF")
2015-05-14 22:35:07 +03:00
{
if (IfDefInElseBranch.Count == 0)
parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation);
IfDefInElseBranch.Pop();
var define_name = IfDefVar.Pop();
if (directiveParams.Count!=0 && directiveParams[0]!=define_name)
parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]);
2015-05-14 22:35:07 +03:00
}
else if (directiveName == "DEFINE")
2015-05-14 22:35:07 +03:00
{
if (!Defines.Contains(directiveParams[0]))
Defines.Add(directiveParams[0]);
2015-05-14 22:35:07 +03:00
}
else if (directiveName == "UNDEF")
2018-01-06 00:29:19 +03:00
{
if (Defines.Contains(directiveParams[0]))
Defines.Remove(directiveParams[0]);
2018-01-06 00:29:19 +03:00
}
parserTools.compilerDirectives.Add(new compiler_directive(new token_info(directiveName), new token_info(string.Join(" ", directiveParams)), CurrentLexLocation));
2015-05-14 22:35:07 +03:00
}
<EXCLUDETEXT>{OneLineCmnt} {
}
<EXCLUDETEXT>{DIRECTIVE} {
parserTools.ParseDirective(yytext, CurrentLexLocation, out directiveName, out directiveParams);
orgDirectiveName = directiveName;
if (directiveName == "") // случай пустой директивы
break;
directiveName = directiveName.ToUpper();
bool addDirective = false;
if (directiveName == "IFDEF")
2015-05-14 22:35:07 +03:00
{
IfDefInElseBranch.Push(false);
IfDefVar.Push(directiveParams[0]);
2015-05-14 22:35:07 +03:00
IfExclude++;
}
else if (directiveName == "IFNDEF")
2015-05-14 22:35:07 +03:00
{
IfDefInElseBranch.Push(false);
IfDefVar.Push(directiveParams[0]);
2015-05-14 22:35:07 +03:00
IfExclude++;
}
else if (directiveName == "ELSE")
2015-05-14 22:35:07 +03:00
{
if (directiveParams.Count!=0 && directiveParams[0]!=IfDefVar.Peek())
parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, IfDefVar.Peek(), directiveParams[0]);
if (IfDefInElseBranch.Count==0 || IfDefInElseBranch.Pop())
parserTools.AddErrorFromResource("UNNECESSARY $else",CurrentLexLocation);
IfDefInElseBranch.Push(true);
2015-05-14 22:35:07 +03:00
if (IfExclude == 1)
{
BEGIN(INITIAL);
addDirective = true;
}
2015-05-14 22:35:07 +03:00
}
else if (directiveName == "ENDIF")
2015-05-14 22:35:07 +03:00
{
if (IfDefInElseBranch.Count == 0)
parserTools.AddErrorFromResource("UNNECESSARY $endif",CurrentLexLocation);
IfDefInElseBranch.Pop();
var define_name = IfDefVar.Pop();
if (directiveParams.Count!=0 && directiveParams[0]!=define_name)
parserTools.AddWarningFromResource("DIFF_DEFINE_NAME", CurrentLexLocation, orgDirectiveName, define_name, directiveParams[0]);
IfExclude--;
2015-05-14 22:35:07 +03:00
if (IfExclude == 0)
{
BEGIN(INITIAL);
addDirective = true;
}
2015-05-14 22:35:07 +03:00
}
if (addDirective)
parserTools.compilerDirectives.Add(new compiler_directive(new token_info(directiveName), new token_info(string.Join(" ", directiveParams)), CurrentLexLocation));
2015-05-14 22:35:07 +03:00
}
<EXCLUDETEXT>.|\n {
}
"{" {
BEGIN(COMMENT);
}
<COMMENT> "}" {
BEGIN(INITIAL);
}
<COMMENT>.|\n {
}
"(*" {
BEGIN(COMMENT1);
}
<COMMENT1> "*)" {
BEGIN(INITIAL);
}
<COMMENT1>.|\n {
}
"|" { return (int)Tokens.tkVertParen; }
[#][#][ \t\r\n]+ { yylval = new Union(); yylval.ti = new token_info("##",CurrentLexLocation); return (int)Tokens.tkShortProgram; }
[#][#][#][ \t\r\n]+ { yylval = new Union(); yylval.ti = new token_info("###",CurrentLexLocation); return (int)Tokens.tkShortSFProgram;
}
2015-05-14 22:35:07 +03:00
"&" { return (int)Tokens.tkAmpersend; }
"," { yylval = new Union(); yylval.ti = new token_info(yytext); return (int)Tokens.tkComma; }
":" { return (int)Tokens.tkColon; }
".." { return (int)Tokens.tkDotDot; }
"." { return (int)Tokens.tkPoint; }
"(" { return (int)Tokens.tkRoundOpen; }
")" { return (int)Tokens.tkRoundClose; }
";" { return (int)Tokens.tkSemiColon; }
"[" { return (int)Tokens.tkSquareOpen; }
"]" { return (int)Tokens.tkSquareClose; }
"?" { return (int)Tokens.tkQuestion; }
"_" { return (int)Tokens.tkUnderscore; }
"?." { return (int)Tokens.tkQuestionPoint; }
"??" { return (int)Tokens.tkDoubleQuestion; }
2017-01-10 08:49:49 +03:00
"?[" { return (int)Tokens.tkQuestionSquareOpen; }
2015-05-14 22:35:07 +03:00
"@" { yylval = new Union(); yylval.op = new op_type_node(Operators.AddressOf); return (int)Tokens.tkAddressOf; }
":=" { yylval = new Union(); yylval.op = new op_type_node(Operators.Assignment); return (int)Tokens.tkAssign; }
"+=" { yylval = new Union(); yylval.op = new op_type_node(Operators.AssignmentAddition); return (int)Tokens.tkPlusEqual; }
"-=" { yylval = new Union(); yylval.op = new op_type_node(Operators.AssignmentSubtraction); return (int)Tokens.tkMinusEqual; }
"*=" { yylval = new Union(); yylval.op = new op_type_node(Operators.AssignmentMultiplication); return (int)Tokens.tkMultEqual; }
"/=" { yylval = new Union(); yylval.op = new op_type_node(Operators.AssignmentDivision); return (int)Tokens.tkDivEqual; }
"-" { yylval = new Union(); yylval.op = new op_type_node(Operators.Minus); return (int)Tokens.tkMinus; }
"+" { yylval = new Union(); yylval.op = new op_type_node(Operators.Plus); return (int)Tokens.tkPlus; }
"/" { yylval = new Union(); yylval.op = new op_type_node(Operators.Division); return (int)Tokens.tkSlash; }
"*" { yylval = new Union(); yylval.op = new op_type_node(Operators.Multiplication); return (int)Tokens.tkStar; }
2017-12-30 00:31:00 +03:00
"**" { yylval = new Union(); yylval.op = new op_type_node(Operators.Power); return (int)Tokens.tkStarStar; }
2015-05-14 22:35:07 +03:00
"=" { yylval = new Union(); yylval.op = new op_type_node(Operators.Equal); return (int)Tokens.tkEqual; }
">" { yylval = new Union(); yylval.op = new op_type_node(Operators.Greater); return (int)Tokens.tkGreater; }
">=" { yylval = new Union(); yylval.op = new op_type_node(Operators.GreaterEqual); return (int)Tokens.tkGreaterEqual; }
"<" { yylval = new Union(); yylval.op = new op_type_node(Operators.Less); return (int)Tokens.tkLower; }
"<=" { yylval = new Union(); yylval.op = new op_type_node(Operators.LessEqual); return (int)Tokens.tkLowerEqual; }
"<>" { yylval = new Union(); yylval.op = new op_type_node(Operators.NotEqual); return (int)Tokens.tkNotEqual; }
"^" { yylval = new Union(); yylval.op = new op_type_node(Operators.Deref); return (int)Tokens.tkDeref; }
"->" { yylval = new Union(); yylval.ti = new token_info(yytext); return (int)Tokens.tkArrow; }
2021-03-02 22:46:43 +03:00
\\[(] { yylval = new Union(); yylval.ti = new token_info(yytext); return (int)Tokens.tkBackSlashRoundOpen; }
\u2192 { yylval = new Union(); yylval.ti = new token_info(yytext); return (int)Tokens.tkArrow; }
2024-04-07 12:02:01 +03:00
\<\<expression\>\> { ExprMode = true; return (int)Tokens.tkParseModeExpression; }
\<\<statement\>\> { ExprMode = true; return (int)Tokens.tkParseModeStatement; }
\<\<type\>\> { ExprMode = true; return (int)Tokens.tkParseModeType; }
2015-05-14 22:35:07 +03:00
\x01 { return (int)Tokens.INVISIBLE; }
2024-04-07 21:42:57 +03:00
[&]?[!]?{ID} {
2015-05-14 22:35:07 +03:00
string cur_yytext = yytext;
int res = Keywords.KeywordOrIDToken(cur_yytext);
currentLexLocation = CurrentLexLocation;
if (res == (int)Tokens.tkIdentifier)
{
2024-04-07 21:42:57 +03:00
if (cur_yytext[0] == '!' && !HiddenIdents && !ExprMode)
parserTools.AddErrorFromResource("UNEXPECTED_SYMBOL{0}",CurrentLexLocation, ""+cur_yytext[0]);
2015-05-14 22:35:07 +03:00
yylval = new Union();
yylval.id = parserTools.create_ident(cur_yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
}
else
switch (res)
{
case (int)Tokens.tkOr:
yylval = new Union();
yylval.op = new op_type_node(Operators.LogicalOR,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkXor:
yylval = new Union();
yylval.op = new op_type_node(Operators.BitwiseXOR,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkAnd:
yylval = new Union();
yylval.op = new op_type_node(Operators.LogicalAND,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkDiv:
yylval = new Union();
yylval.op = new op_type_node(Operators.IntegerDivision,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkMod:
yylval = new Union();
yylval.op = new op_type_node(Operators.ModulusRemainder,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkShl:
yylval = new Union();
yylval.op = new op_type_node(Operators.BitwiseLeftShift,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkShr:
yylval = new Union();
yylval.op = new op_type_node(Operators.BitwiseRightShift,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkNot:
yylval = new Union();
yylval.op = new op_type_node(Operators.LogicalNOT,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkAs:
yylval = new Union();
yylval.op = new op_type_node(Operators.As,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkIn:
yylval = new Union();
yylval.op = new op_type_node(Operators.In,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkIs:
yylval = new Union();
yylval.op = new op_type_node(Operators.Is,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkImplicit:
yylval = new Union();
yylval.op = new op_type_node(Operators.Implicit,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkExplicit:
yylval = new Union();
yylval.op = new op_type_node(Operators.Explicit,currentLexLocation);
yylval.op.text = cur_yytext;
break;
case (int)Tokens.tkSizeOf:
case (int)Tokens.tkTypeOf:
case (int)Tokens.tkWhere:
case (int)Tokens.tkArray:
case (int)Tokens.tkCase:
case (int)Tokens.tkClass:
case (int)Tokens.tkAuto:
case (int)Tokens.tkConst:
case (int)Tokens.tkConstructor:
case (int)Tokens.tkDestructor:
case (int)Tokens.tkDo:
case (int)Tokens.tkElse:
case (int)Tokens.tkExcept:
case (int)Tokens.tkFile:
case (int)Tokens.tkFinalization:
case (int)Tokens.tkFinally:
case (int)Tokens.tkFor:
2017-06-08 17:56:17 +03:00
case (int)Tokens.tkLoop:
2015-05-14 22:35:07 +03:00
case (int)Tokens.tkForeach:
case (int)Tokens.tkFunction:
case (int)Tokens.tkIf:
case (int)Tokens.tkImplementation:
case (int)Tokens.tkInherited:
case (int)Tokens.tkInitialization:
case (int)Tokens.tkInterface:
case (int)Tokens.tkProcedure:
case (int)Tokens.tkOperator:
case (int)Tokens.tkProperty:
case (int)Tokens.tkRaise:
case (int)Tokens.tkRecord:
case (int)Tokens.tkRepeat:
case (int)Tokens.tkSet:
case (int)Tokens.tkType:
case (int)Tokens.tkThen:
case (int)Tokens.tkUntil:
case (int)Tokens.tkUses:
case (int)Tokens.tkVar:
case (int)Tokens.tkWhile:
case (int)Tokens.tkWith:
case (int)Tokens.tkNil:
case (int)Tokens.tkGoto:
case (int)Tokens.tkOf:
case (int)Tokens.tkLabel:
case (int)Tokens.tkLock:
case (int)Tokens.tkProgram:
case (int)Tokens.tkEvent:
case (int)Tokens.tkDefault:
case (int)Tokens.tkTemplate:
case (int)Tokens.tkExports:
case (int)Tokens.tkResourceString:
case (int)Tokens.tkThreadvar:
case (int)Tokens.tkSealed:
case (int)Tokens.tkPartial:
case (int)Tokens.tkParams:
case (int)Tokens.tkTo:
case (int)Tokens.tkDownto:
case (int)Tokens.tkUnit:
2017-09-24 13:12:27 +03:00
case (int)Tokens.tkNamespace:
2015-05-14 22:35:07 +03:00
case (int)Tokens.tkLibrary:
case (int)Tokens.tkExternal:
case (int)Tokens.tkYield:
2018-12-25 23:18:49 +03:00
case (int)Tokens.tkSequence:
2017-02-20 13:57:13 +03:00
case (int)Tokens.tkMatch:
2018-05-01 19:29:39 +03:00
case (int)Tokens.tkWhen:
2018-09-22 18:49:47 +03:00
case (int)Tokens.tkStatic:
2022-02-21 17:03:34 +03:00
case (int)Tokens.tkStep:
case (int)Tokens.tkAsync:
case (int)Tokens.tkAwait:
2015-05-14 22:35:07 +03:00
yylval = new Union();
yylval.ti = new token_info(cur_yytext,currentLexLocation);
break;
case (int)Tokens.tkBegin:
case (int)Tokens.tkEnd:
case (int)Tokens.tkTry:
yylval = new Union();
yylval.ti = new token_info(cur_yytext,currentLexLocation);
break;
case (int)Tokens.tkNew:
case (int)Tokens.tkOn:
case (int)Tokens.tkName:
case (int)Tokens.tkPrivate:
case (int)Tokens.tkProtected:
case (int)Tokens.tkPublic:
case (int)Tokens.tkInternal:
case (int)Tokens.tkRead:
case (int)Tokens.tkWrite:
case (int)Tokens.tkIndex:
2015-05-14 22:35:07 +03:00
yylval = new Union();
yylval.id = new ident(cur_yytext,currentLexLocation);
break;
case (int)Tokens.tkAbstract:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_abstract,currentLexLocation);
yylval.id.name = cur_yytext;
break;
case (int)Tokens.tkForward:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_forward,currentLexLocation);
yylval.id.name = cur_yytext;
break;
case (int)Tokens.tkOverload:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_overload,currentLexLocation);
yylval.id.name = cur_yytext;
break;
case (int)Tokens.tkReintroduce:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_reintroduce,currentLexLocation);
yylval.id.name = cur_yytext;
break;
case (int)Tokens.tkOverride:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_override,currentLexLocation);
yylval.id.name = cur_yytext;
break;
2015-10-10 21:37:34 +03:00
case (int)Tokens.tkExtensionMethod:
2015-10-10 20:38:09 +03:00
yylval = new Union();
2015-10-10 21:37:34 +03:00
yylval.id = new procedure_attribute(proc_attribute.attr_extension,currentLexLocation);
2015-10-10 20:38:09 +03:00
yylval.id.name = cur_yytext;
break;
2015-05-14 22:35:07 +03:00
case (int)Tokens.tkVirtual:
yylval = new Union();
yylval.id = new procedure_attribute(proc_attribute.attr_virtual,currentLexLocation);
yylval.id.name = cur_yytext;
break;
}
return res;
}
{INTNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.ex = parserTools.create_int_const(yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
return (int)Tokens.tkInteger;
}
{BIGINTNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.ex = parserTools.create_bigint_const(yytext,currentLexLocation);
return (int)Tokens.tkBigInteger;
}
2015-05-14 22:35:07 +03:00
{HEXNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.ex = parserTools.create_hex_const(yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
return (int)Tokens.tkHex;
}
{FLOATNUM} |
{EXPNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.ex = parserTools.create_double_const(yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
return (int)Tokens.tkFloat;
}
{STRINGNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.stn = parserTools.create_string_const(yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
return (int)Tokens.tkStringLiteral;
}
{MULTILINESTRINGNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.stn = parserTools.create_multiline_string_const(yytext,currentLexLocation);
return (int)Tokens.tkMultilineStringLiteral;
}
2018-03-21 23:01:54 +03:00
{FORMATSTRINGNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.stn = parserTools.create_format_string_const(yytext,currentLexLocation);
2018-03-21 23:01:54 +03:00
return (int)Tokens.tkFormatStringLiteral;
}
2015-05-14 22:35:07 +03:00
{SHARPCHARNUM} {
yylval = new Union();
currentLexLocation = CurrentLexLocation;
yylval.stn = parserTools.create_sharp_char_const(yytext,currentLexLocation);
2015-05-14 22:35:07 +03:00
return (int)Tokens.tkAsciiChar;
}
{OLDDIRECTIVE} {
yylval = new Union();
yylval.id = new ident(yytext,CurrentLexLocation);
return (int)Tokens.tkDirectiveName;
}
[^ \r\n\t] {
parserTools.AddErrorFromResource("UNEXPECTED_SYMBOL{0}",CurrentLexLocation, yytext);
2015-05-14 22:35:07 +03:00
return -1;
}
%{
if (currentLexLocation != null)
yylloc = currentLexLocation;
else
yylloc = CurrentLexLocation;
currentLexLocation = null;
%}
%%
public LexLocation CurrentLexLocation
{
get {
return new LexLocation(tokLin, tokCol, tokELin, tokECol, parserTools.currentFileName);
2015-05-14 22:35:07 +03:00
}
}
protected override bool yywrap()
{
if (IfDefInElseBranch.Count != 0)
parserTools.AddErrorFromResource("ENDIF_ABSENT",CurrentLexLocation);
2015-05-14 22:35:07 +03:00
BEGIN(INITIAL);
if (buffStack.Count == 0)
return true;
RestoreBuffCtx(buffStack.Pop());
parserTools.currentFileName = fNameStack.Pop();
2015-05-14 22:35:07 +03:00
return false;
}
public override void yyerror(string format, params object[] args)
{
string errorMsg = parserTools.CreateErrorString(yytext,args);
parserTools.AddError(errorMsg,CurrentLexLocation);
2015-05-14 22:35:07 +03:00
}
private void TryInclude(string fName)
{
if (fName == null || fName.Length == 0)
parserTools.AddErrorFromResource("INCLUDE_EMPTY_FILE",CurrentLexLocation);
2015-05-14 22:35:07 +03:00
else
try {
if (fName.StartsWith("'"))
{
fName = fName.Substring(1);
if (fName.EndsWith("'"))
fName = fName.Substring(0, fName.Length-1);
}
BufferContext savedCtx = MkBuffCtx();
string full_path = fName;
if (!Path.IsPathRooted(full_path))
full_path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(parserTools.currentFileName), fName));
2018-10-26 20:12:42 +03:00
if (fNameStack.Contains(full_path))
{
parserTools.AddErrorFromResource("RECUR_INCLUDE", CurrentLexLocation, fName);
2018-10-26 20:12:42 +03:00
return;
}
2015-05-14 22:35:07 +03:00
SetSource(File.ReadAllText(full_path), 0);
fNameStack.Push(parserTools.currentFileName);
parserTools.currentFileName = full_path;
2015-05-14 22:35:07 +03:00
buffStack.Push(savedCtx);
}
catch
{
parserTools.AddErrorFromResource("INCLUDE_COULDNT_OPEN_FILE{0}",CurrentLexLocation,fName);
2015-05-14 22:35:07 +03:00
}
}
// Статический класс, определяющий ключевые слова языка, находится в файле Keywords.cs