View Issue Details

IDProjectCategoryView StatusLast Update
00019711003.1(2024)/Issue8Shell and Utilitiespublic2026-03-26 16:24
ReporterLove4Boobies Assigned Tomsbrown  
PrioritynormalSeverityEditorialTypeEnhancement Request
Status ResolvedResolutionAccepted As Marked 
NameBogdan Barbu
Organization
User Reference
Sectionlex
Page Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/utilities/lex.html
Line NumberN/A
Interp Status---
Final Accepted Text
Summary0001971: Changing lex prefixes
DescriptionThe yacc utility has a -p option that allows the use of a prefix other than the default "yy" - which is useful when linking multiple parsers in the same program/library. Alas, lex does not have a similar option even though they are supposed to be used together. This is an interface mismatch.
Desired Actionflex has a -P option that does exactly this, we might want to standardize it. I'm not sure whether implementations other than flex are realistically still in use today but I did look at the historical lex implementation, at IBM's and Heirloom's documentation for lex and a -P option would not be in conflict with these implementations.

As a side note, we should ideally also standardize the re-entrancy support found in flex/bison. This would allow programs to instantiate as many concurrent lexers and parsers as they want. The only standard way to do this today is to use arcane locking hacks.
Tagsissue9

Activities

msbrown

2026-03-05 16:38

manager   bugnote:0007385

Would you please propose some wording for this option, that we can use as a starting place? Or, if you prefer, point us to a specific wording that you would like to see adopted by the committee?

Guy Harris

2026-03-05 17:49

reporter   bugnote:0007387

The FreeBSD manual page at https://man.freebsd.org/cgi/man.cgi?query=flex&apropos=0&sektion=0&manpath=FreeBSD+15.0-RELEASE+and+Ports&format=html says:

-Pprefix, --prefix=STRING
          changes the default yy prefix used by flex for all globally-vis-
          ible variable and function names to instead be prefix. For ex-
          ample, -Pfoo changes the name of yytext to footext. It also
          changes the name of the default output file from lex.yy.c to
          lex.foo.c. ...

That's taken from the Flex Texinfo documentation at https://github.com/westes/flex/blob/master/doc/flex.texi.

Guy Harris

2026-03-05 17:51

reporter   bugnote:0007388

> As a side note, we should ideally also standardize the re-entrancy support found in flex/bison. This would allow programs to instantiate as many concurrent lexers and parsers as they want.

Yes - flex and both bison and Berkeley YACC.

> The only standard way to do this today is to use arcane locking hacks.

Yes, so libpcap, for example, now *requires* both Flex and either Bison or Berkeley YACC to build.

Love4Boobies

2026-03-06 08:12

reporter   bugnote:0007390

Change SYNOPSIS to:

lex [-t] [-n|-v] [-P sym_prefix] [file...]

---

Add to OPTIONS:

-P sym_prefix

Use sym_prefix instead of yy as the prefix for all external names produced by lex. The names affected shall include yylex(), yymore(), yyless(), and yywrap(), and the variables yytext, yyleng, and yyin. (In the remainder of this section, the six symbols cited are referenced using their default names only as a notation convenience.) Local names may also be affected by the -P option.

---

Change last paragraph in EXTENDED DESCRIPTION from:

Except for input(), unput(), and main(), all external and static names generated by lex shall begin with the prefix yy or YY.

to:

The lex library interfaces need not support interfaces with other than the default yy symbol prefix.

Except for input(), unput(), and main(), all external and static names generated by lex shall begin with the prefix yy or YY. If the -P option is used, external names that would otherwise beign with yy shall instead begin with sym_prefix.

---

Add to APPLICATION USAGE:

When the -P option is used with a prefix other than yy, applications should not rely on the default versions of yywrap() and main() from the lex library, because those interfaces need only support scanners generated with the default symbol prefix.

msbrown

2026-03-26 16:18

manager   bugnote:0007416

Last edited: 2026-03-26 16:24

Final Accepted text for Issue 9:

At page 3037 line 101680 Change

    
lex [-t] [-n|-v]  [file...]


to

    
lex [-t] [-n|-v] [-P sym_prefix] [file...]



At page 3037 after line 01693 Add:

-P sym_prefix
    Use sym_prefix instead of yy as the prefix for all external names produced by lex. The names affected shall include yylex(), yymore(), yyless(), and yywrap(), and the variables yytext, yyleng, and yyin. In the remainder of this section, the symbols cited are referenced using their default names only as a notation convenience.
    If the -t option is not specified, write the resulting program to lex.sym_prefix.c instead of lex.yy.c.

At page 3038, line 101758, change the entire OUTPUT FILES section to:
    

    A text file containing C source code shall be written to the first applicable item in this list:
        

            
  1. Standard output if the -t option is given

  2.         
  3. A file named lex.sym_prefix.c if the -P option is given

  4.         
  5. A file named lex.yy.c otherwise

  6.         

      

At page 3045 line 102032 Change:

Except for input(), unput(), and main(), all external and static names generated by lex shall begin with the prefix yy or YY.

to:

The lex library interfaces need not support interfaces with other than the default yy symbol prefix.

The functions input(), unput(), and main() shall not be prefixed. All other external and static names generated by lex shall begin with sym_prefix if the -P option was specified, otherwise they shall begin with yy or YY.

    
At page 3045 after line 102054 Add:

When the -P option is used with a prefix other than yy, applications should not rely on the default versions of yywrap() and main() from the lex library, because those interfaces need only support scanners generated with the default symbol prefix.

Issue History

Date Modified Username Field Change
2026-01-24 11:54 Love4Boobies New Issue
2026-03-05 16:38 msbrown Note Added: 0007385
2026-03-05 17:49 Guy Harris Note Added: 0007387
2026-03-05 17:51 Guy Harris Note Added: 0007388
2026-03-06 08:12 Love4Boobies Note Added: 0007390
2026-03-26 16:16 msbrown Tag Attached: issue9
2026-03-26 16:18 msbrown Assigned To => msbrown
2026-03-26 16:18 msbrown Status New => Resolved
2026-03-26 16:18 msbrown Resolution Open => Accepted As Marked
2026-03-26 16:18 msbrown Interp Status => ---
2026-03-26 16:18 msbrown Note Added: 0007416
2026-03-26 16:20 msbrown Note Edited: 0007416
2026-03-26 16:21 nick Note Edited: 0007416
2026-03-26 16:24 nick Note Edited: 0007416