%{
+
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of GLD, the Gnu Linker.
char *buystring();
-int lineno = 1;
+unsigned int lineno = 1;
int old;
+static comment();
+
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
#undef YY_FATAL_ERROR
unsigned int include_stack_ptr = 0;
-/* FOUR STATES
+/* STATES
COMMAND on command line
COMMENT in a C comment
EXPRESSION definiatelyt in an expression
SCRIPT definately in a script
SOMEWHERE either EXPRESSION or SCRIPT
+ MRI in an MRI script
*/
#define RTOKEN(x) { yylval.token = x; return x; }
%}
%a 4000
%o 5000
-FILENAMECHAR1 [_a-zA-Z\/\.\\]
-FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\]
+
+CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
+CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
+FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
+SYMBOLCHARN [_a-zA-Z\/\.\\0-9]
+FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
FILENAME {FILENAMECHAR}+
WHITE [ \t\n]+
-%x COMMAND
-%x SCRIPT
-%x EXPRESSION
-%x COMMENT
-%x BOTH
+NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
+
+
+%s COMMAND
+%s SCRIPT
+%s EXPRESSION
+%s COMMENT
+%s BOTH
+%s DEFSYMEXP
+%s MRI
%%
-
-<COMMAND>"-defsym" { return OPTION_defsym; }
+
+
+<BOTH,SCRIPT,EXPRESSION,COMMAND>"/*" { comment(); }
+
+
+<DEFSYMEXP>"-" { RTOKEN('-');}
+<DEFSYMEXP>"+" { RTOKEN('+');}
+<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
+<DEFSYMEXP>[ \t] { RTOKEN(DEFSYMEND); }
+<DEFSYMEXP>"=" { RTOKEN('='); }
+<COMMAND>"-defsym"{WHITE}* { return OPTION_defsym; }
<COMMAND>"-noinhibit_exec" { return OPTION_noinhibit_exec; }
<COMMAND>"-noinhibit-exec" { return OPTION_noinhibit_exec; }
<COMMAND>"-sort_common" { return OPTION_sort_common;}
return OPTION_F;
}
+<COMMAND>"-y"{FILENAME} {
+ yylval.name = buystring(yytext+2);
+ return OPTION_y;
+ }
+
<COMMAND>"-A"{FILENAME} {
yylval.name = buystring(yytext+2);
return OPTION_Aarch;
}
-<BOTH,EXPRESSION>"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
- yylval.integer = strtol(yytext,0,hex_mode);
+
+<COMMAND>"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; }
+
+<MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
+ yylval.integer = strtoul(yytext+1, 0,16);
+ return INT;
+ }
+
+<MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) {
+ int base ;
+ switch (yytext[yyleng-1]) {
+ case 'X':
+ case 'H':
+ base = 16;
+ break;
+ case 'O':
+ base = 8;
+ break;
+ case 'B':
+ base = 2;
+ break;
+ default:
+ base = 10;
+ }
+ yylval.integer = strtoul(yytext+1, 0, base);
+ return INT;
+ }
+<DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
+ yylval.integer = strtoul(yytext,0,hex_mode);
if (yytext[yyleng-1]=='M'
|| yytext[yyleng-1] == 'm') {
yylval.integer *= 1024*1024;
<BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);}
<BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);}
<BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
-<BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');}
+<MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');}
<BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');}
<BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');}
<BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');}
<BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');}
<BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');}
<BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
-<BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');}
+<MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');}
<BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; }
<BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); }
<BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');}
<BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
<BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
<BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
+<MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
+<MRI>"*".* { /* Mri comment line */ }
+<MRI>"END" { RTOKEN(ENDWORD); }
+<MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
+<MRI>"ALIGN" { RTOKEN(ALIGN_K);}
+
+<MRI>"CHIP" { RTOKEN(CHIP); }
+<MRI>"BASE" { RTOKEN(BASE); }
+<MRI>"ALIAS" { RTOKEN(ALIAS); }
+<MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
+<MRI>"LOAD" { RTOKEN(LOAD); }
+<MRI>"PUBLIC" { RTOKEN(PUBLIC); }
+<MRI>"ORDER" { RTOKEN(ORDER); }
+<MRI>"NAME" { RTOKEN(NAMEWORD); }
+<MRI>"FORMAT" { RTOKEN(FORMAT); }
+<MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
+<MRI>"SECT" { RTOKEN(SECT); }
+<EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
+<MRI>"end" { RTOKEN(ENDWORD); }
+<MRI>"chip" { RTOKEN(CHIP); }
+<MRI>"load" { RTOKEN(LOAD); }
+<MRI>"order" { RTOKEN(ORDER); }
+<MRI>"name" { RTOKEN(NAMEWORD); }
+<MRI>"format" { RTOKEN(FORMAT); }
+<MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
+<MRI>"sect" { RTOKEN(SECT); }
+<EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
+
+<COMMAND>{CMDFILENAMECHAR1}{CMDFILENAMECHAR}* {
+ yylval.name = buystring(yytext);
+ return NAME;
+ }
+
+
+<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
+/* Filename without commas, needed to parse mri stuff */
+ yylval.name = buystring(yytext);
+ return NAME;
+ }
+
<BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
yylval.name = buystring(yytext);
return NAME;
}
<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
-<COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t]
-
-"/*" { old = INITIAL; BEGIN(COMMENT); }
-<COMMAND>"/*" { old = COMMAND; BEGIN(COMMENT); }
-<BOTH>"/*" { old =BOTH; BEGIN(COMMENT); }
-<SCRIPT>"/*" { old = EXPRESSION; BEGIN(COMMENT); }
-<EXPRESSION>"/*" { old = SCRIPT; BEGIN(COMMENT); }
-"/*" { old = INITIAL; BEGIN(COMMENT); }
-<COMMENT>[^*\\n]*
-<COMMENT>"*"+[^*/\\n]*
-<COMMENT>\\n { ++lineno;}
-<COMMENT>"*"+"/" { BEGIN(old); }
+<MRI,COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t]
<<EOF>> {
include_stack_ptr--;
return END;
}
-
-
-
-
-
-
-
%%
void
void
+DEFUN_VOID(ldlex_mri_script)
+{
+*(state_stack_p)++ = yy_start;
+BEGIN(MRI);
+}
+
+void
+DEFUN_VOID(ldlex_defsym)
+{
+*(state_stack_p)++ = yy_start;
+BEGIN(DEFSYMEXP);
+}
+
+void
DEFUN_VOID(ldlex_expression)
{
*(state_stack_p)++ = yy_start;
}
}
+static
+comment()
+{
+ int c;
+ while (1)
+ {
+ c = input();
+ while (c !='*' && c != EOF)
+ {
+ if (c == '\n') lineno++;
+ c = input();
+ }
+
+
+ if (c == '*')
+ {
+ c = input();
+ while ( c == '*')
+ c = input();
+ if ( c == '/' )
+ break; /* found the end */
+ }
+
+ if ( c == EOF )
+ {
+ einfo( "%F%P :EOF in comment");
+ break;
+ }
+ }
+}